from tkinter import *
def simpNumber(a):
    f = True
    i = 2
    while f:
        if a % i == 0:
            f = False
            break
        i += 1
        if i > a/2:
            break
    if a == 1:
        f = False
    return f
ls = []
listSimp = []
Max = 1
num = input()
k = True
if len(num) == 4:
    for i in range(4):
        if num[i] not in "0123456789":
            print(0)
            k = False
            break
    if k == True:
        for i in range(4):
            ls.append(int(num[i]))
        for i in range(3):
            ls.append(int(num[i]+num[i+1]))
        for i in range(2):
            ls.append(int(num[i]+num[i+1]+num[i+2]))
        ls.append(int(num))
        for i in range(len(ls)):
            if simpNumber(ls[i]) == True:
                listSimp.append(ls[i])
else:
    print(0)

if  len(listSimp) > 0:
    if listSimp[-1] != 1:
        print(listSimp[-1])
    



    
    
